home *** CD-ROM | disk | FTP | other *** search
- unit CustomU2;
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons;
-
- type
- TForm1 = class(TForm)
- LstVariable: TListBox;
- BtnFindIt: TSpeedButton;
- BtnDoIt: TBitBtn;
- EdtDir: TEdit;
- OpenDialog1: TOpenDialog;
- CmbVariable: TComboBox;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure BtnDoItClick(Sender: TObject);
- procedure BtnFindItClick(Sender: TObject);
- procedure LstVariableMeasureItem(Control: TWinControl; Index: Integer;
- var Height: Integer);
- procedure LstVariableDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- procedure CmbVariableMeasureItem(Control: TWinControl; Index: Integer;
- var Height: Integer);
- procedure CmbVariableDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- public
- Bmps: TStrings;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- procedure EmptyBmpList(S: TStrings);
- begin
- with S do
- while Count > 0 do
- begin
- Objects[0].Free;
- Delete(0);
- end;
- end;
-
- procedure LoadBitmaps(const Path: String; S: TStrings);
- var
- Bmp: TBitmap;
- SearchRec: TSearchRec;
- begin
- EmptyBmpList(S);
- with S do
- begin
- BeginUpdate;
- if FindFirst(Path + '*.bmp', faAnyFile, SearchRec) = 0 then
- try
- repeat
- Bmp := TBitmap.Create;
- Bmp.LoadFromFile(Path + SearchRec.Name);
- AddObject(SearchRec.Name, Bmp);
- until FindNext(SearchRec) <> 0;
- finally
- FindClose(SearchRec);
- end;
- EndUpdate;
- end;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Bmps := TStringList.Create
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- EmptyBmpList(Bmps);
- Bmps.Free;
- end;
-
- procedure TForm1.BtnDoItClick(Sender: TObject);
- begin
- if Length(EdtDir.Text) = 0 then
- raise Exception.Create('Type a path in the edit control');
- if EdtDir.Text[Length(EdtDir.Text)] <> '\' then
- EdtDir.Text := EdtDir.Text + '\';
- Screen.Cursor := crHourGlass;
- try
- LoadBitmaps(EdtDir.Text, Bmps);
- finally
- Screen.Cursor := crDefault;
- end;
- TStringList(Bmps).Sort;
- LstVariable.Items := Bmps;
- CmbVariable.Items := Bmps;
- end;
-
- procedure TForm1.BtnFindItClick(Sender: TObject);
- begin
- with OpenDialog1 do
- begin
- InitialDir := EdtDir.Text;
- if Execute then
- begin
- EdtDir.Text := ExtractFilePath(FileName);
- BtnDoIt.Click
- end
- end
- end;
-
- procedure TForm1.LstVariableMeasureItem(Control: TWinControl;
- Index: Integer; var Height: Integer);
- begin
- if Index >= 0 then
- with Bmps do
- if Objects[Index] <> nil then
- Height := TBitmap(Objects[Index]).Height;
- end;
-
- procedure TForm1.LstVariableDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- var
- Bmp: TBitmap;
- R: TRect;
- begin
- with LstVariable, Items, Canvas, Rect do
- begin
- FillRect(Rect);
- Bmp := TBitmap(Objects[Index]);
- Draw(Left, Top, Bmp);
- if odSelected in State then
- begin
- R := Bounds(Left, Top, Bmp.Width, Bmp.Height);
- InvertRect(Handle, R)
- end;
- end
- end;
-
- procedure TForm1.CmbVariableMeasureItem(Control: TWinControl;
- Index: Integer; var Height: Integer);
- begin
- if Index >= 0 then
- with Bmps do
- if Objects[Index] <> nil then
- Height := TBitmap(Objects[Index]).Height;
- end;
-
- procedure TForm1.CmbVariableDrawItem(Control: TWinControl; Index: Integer;
- Rect: TRect; State: TOwnerDrawState);
- var
- Bmp: TBitmap;
- R: TRect;
- begin
- with CmbVariable, Items, Canvas, Rect do
- begin
- FillRect(Rect);
- Bmp := TBitmap(Objects[Index]);
- Draw(Left, Top, Bmp);
- if odSelected in State then
- begin
- R := Bounds(Left, Top, Bmp.Width, Bmp.Height);
- InvertRect(Handle, R)
- end;
- end
- end;
-
- end.
-